<script type="text/javascript" src="/application/echarts/echarts.min.js"></script>




<fieldset class="layui-elem-field layui-field-title" >
    <legend>30天订单统计</legend>
</fieldset>



<!-- 这个是图表 -->
<div id="month_ehart" style="width:100%;height:250px;padding: 0;overflow-x:auto;overflow-y: hidden"></div>




<?

//获取最近30天 的订单和金额
$limit_day   = date("Y-m-d 00:00:00", strtotime("-30 day"));
$order       = select_lines_items($table_prefix . "order", "", "add_date,price", "add_date > '" . $limit_day . "'", "");
$order_date  = transform_2darray_in_1darray_number_as_key($order, "add_date");
$order_price = transform_2darray_in_1darray_with_new_key($order,"add_date","price");




//循环最近三十天
for($i=0;$i<30;$i++)
{
    $echart_month[]=date("m-d",strtotime("-$i day"));

    //统计订单数
    $p['data']=$order_date;
    $p['rang']="like";
    $p['target']=date("m-d",strtotime("-$i day"));
    $month_order[]=count_num_in_array($p);

    //统计订单金额

    $_this_day_price=0;

    foreach($order_price as $k=>$v)
    {
        if(date("m-d",strtotime("-$i day")) == substr($k,5,5))
        {
            $_this_day_price=$_this_day_price+$v;
        }

    }

    $month_price[]=$_this_day_price;

}



?>

<? $echart_month_srt=implode(array_reverse($echart_month),"','")?>
<?// $echart_income_srt=implode($month_income,"','")?>
<?// $echart_outport_srt=implode($month_outport,"','")?>
<? $echart_order_srt=implode(array_reverse($month_order),",")?>
<? $echart_price_srt=implode(array_reverse($month_price),",")?>





<script type="text/javascript">
    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('month_ehart'));

    // 指定图表的配置项和数据
    var option = {
        title: {
            text: ''
        },
        tooltip: {},
        legend: {
            data: ['运单','金额']
        },
        xAxis: {
            data: ['<?echo $echart_month_srt?>']
        },
        yAxis: {},
        series: [
            {
                name: '运单',
                type: 'bar',
                color: ['#009688'],
                data: [<?echo $echart_order_srt?>]
            },
            {
                name: '金额',
                type: 'bar',
                color: ['#ff9900'],
                data: [<?echo $echart_price_srt?>]
            }
        ]
    };

    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
</script>

